package com.sanjin.convert;

import com.sanjin.entity.ParkLot;
import com.sanjin.entity.ParkSpace;
import com.sanjin.form.ParkLotForm;
import com.sanjin.service.ParkSpaceService;
import com.sanjin.vo.PageVo;
import com.sanjin.vo.ParkLotVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/5 14:08
 */
@Component
public class ParkLotConvert {

    @Autowired
    private ParkSpaceService parkSpaceService;

    /**
     * ParkLotForm to ParkLot
     *
     * @param parkLotForm
     * @return
     */
    public ParkLot parkLotForm2ParkLot(ParkLotForm parkLotForm) {
        ParkLot parkLot = new ParkLot();
        BeanUtils.copyProperties(parkLotForm, parkLot);
        return parkLot;
    }

    public ParkLotVo parkLot2ParkLotVo(ParkLot parkLot) {
        ParkLotVo parkLotVo = new ParkLotVo();
        BeanUtils.copyProperties(parkLot,parkLotVo);
        // 填充 停车位信息
        List<ParkSpace> parkSpaces = parkSpaceService.queryParkSpacesByParkLotId(parkLot.getId());
        parkLotVo.setParkSpaceList(parkSpaces);
        return parkLotVo;
    }
}
